/**
 * 门店设置的Route Component
 * @author: minzhang
 * @update: 2016-10-13
 */

import React, { PropTypes } from 'react';
import { connect } from 'dva';
import StoreSettingMenu from '../../components/StoreSetting/StoreSettingMenu';
import StoreInfoForm from '../../components/StoreInfo/StoreInfoForm';
import StoreInfoModal from '../../components/StoreInfo/StoreInfoModal';
import styles from './StoreInfo.less';

function StoreInfo({ location, dispatch, storeInfo }) {
	const {
		loading, btnLoading, item, mainMapList, envMapList, isAllDay, dayilyBillTime, phone,
		step, modalVisible, modalLoading, modalBtnLoading,
		previewVisible, previewImage, previewImageName, 
  } = storeInfo;
	
	// 表单的属性
	const storeInfoFormProps = {
		loading,
		btnLoading,
		phone,
		item,
		mainMapList,
		envMapList,
		isAllDay,
		dayilyBillTime,
		onPhoneChange() {
			dispatch({
        type: 'storeInfo/showModal',
      });
		},
		onBillTimeChange(time) {
			dispatch({
        type: 'storeInfo/updateAction',
        payload: {
					dayilyBillTime: time
				},
      });
		},
		onUploadChange(file) {
//			dispatch({
//        type: 'storeInfo/showPreviewModal',
//        payload: {
//					previewImage: file.url,
//					previewImageName: file.name,
//				},
//      });
		},
		onUploadRemove(file) {
//			dispatch({
//        type: 'storeInfo/showPreviewModal',
//        payload: {
//					previewImage: file.url,
//					previewImageName: file.name,
//				},
//      });
		},
		onPreview(file) {
//			dispatch({
//        type: 'storeInfo/showPreviewModal',
//        payload: {
//					previewImage: file.url,
//					previewImageName: file.name,
//				},
//      });
		},
		onSwitchChange(checked) {
			dispatch({
				type: 'storeInfo/updateAction',
				payload: {
					isAllDay: checked,
				}
			});
		},
		onOk(data) {
			debugger
		}
	};
	
	// modal的属性
	const storeInfoModalProps = {
		step, 
		phone,
		visible: modalVisible, 
		modalLoading, 
		modalBtnLoading,
		onConfirm() {
			dispatch({
        type: 'storeInfo/updateAction',
				payload: {
					step: step + 1
				}
      });
		},
		onCancel() {
			dispatch({
        type: 'storeInfo/hideModal',
      });
		},
	}
	
	//图片预览
	const commonPreviewModalProps = {
		previewVisible,
		previewImage,
		previewImageName,
		onPreviewCancel() {
			dispatch({
        type: 'goodManage/hidePreviewModal',
      });
		},
	};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  return (
		<div>
			<StoreSettingMenu current={location.pathname} />
			<div className="page-content" style={{height: 'calc(100vh - 142px)'}}>
				<StoreInfoForm { ...storeInfoFormProps } />
				<StoreInfoModal { ...storeInfoModalProps } />
			</div>
		</div>
  );
}

StoreInfo.propTypes = {
	location: PropTypes.object,
	dispatch: PropTypes.func,
  storeInfo: PropTypes.object,
};

export default connect(({ storeInfo }) => ({ storeInfo }))(StoreInfo);